#! /usr/bin/make -f
# debian/rules file - for lynx (2.8.5)
# Based on sample debian/rules file - for GNU Hello (1.3).
# Copyright 1994, 1995 by Ian Jackson.
# Copyright 2002, 2003, 2004 James Troup
# I hereby give you perpetual unlimited permission to copy,
# modify and relicense this file, provided that you do not remove
# my name from the file itself.  (I assert my moral right of
# paternity under the Copyright, Designs and Patents Act 1988.)
# This file may have to be extensively modified

install_dir=install -d -m 755
install_file=install -m 644
install_script=install -m 755
install_binary=install -m 755 -s

include /usr/share/dpatch/dpatch.make

build: patch-stamp
	$(checkdir)
	./configure --prefix=/usr \
		    --libexecdir=/usr/lib --sysconfdir=/etc \
		    --localstatedir=/var --libdir=/etc \
		    --enable-warnings \
		    --with-screen=ncursesw \
		    --enable-externs \
		    --enable-cgi-links --enable-exec-links \
		    --enable-exec-scripts \
		    --enable-nls \
		    --enable-charset-choice \
		    --enable-default-colors \
		    --enable-ipv6 \
		    --enable-nested-tables --enable-read-eta \
		    --enable-nsl-fork --enable-justify-elts --enable-color-style \
		    --without-gnutls \
		    --with-zlib \
		    --with-bzlib
	$(MAKE)
	touch build

clean: unpatch
	$(checkdir)
	-rm -rf build debian/tmp debian/files debian/substvars debian/patched
	-(find . -type f -name \*~ | xargs rm)
	-$(MAKE) distclean
	-rm -f config.cache config.log lynx 
	rm -f debian/icons/web-browser.png

binary-indep:

binary-arch: checkroot build
	$(checkdir)
	-rm -rf debian/tmp/
	$(install_dir) debian/tmp/DEBIAN/
	$(install_script) debian/preinst debian/postinst debian/prerm debian/postrm debian/tmp/DEBIAN/
	$(install_file) debian/conffiles debian/tmp/DEBIAN/

	$(install_dir) debian/tmp/usr/bin/
	$(install_binary) lynx debian/tmp/usr/bin/lynx.stable

	$(install_dir) debian/tmp/etc/
	$(install_file) lynx.cfg debian/tmp/etc/
	$(install_file) samples/lynx.lss debian/tmp/etc/

	$(install_dir) debian/tmp/usr/share/man/man1/
	$(install_file) lynx.man debian/tmp/usr/share/man/man1/lynx.1
	find debian/tmp/usr/share/man/ -type f -print | xargs gzip -9

	$(install_dir) debian/tmp/usr/share/locale/
	for f in po/*.gmo; do \
		cat=`basename $$f`; \
		lang=`echo $$cat | sed 's/\.gmo$$//'`; \
		$(install_dir) debian/tmp/usr/share/locale/$$lang/LC_MESSAGES; \
		$(install_file) $$f debian/tmp/usr/share/locale/$$lang/LC_MESSAGES/lynx.mo; \
	done

	$(install_dir) debian/tmp/usr/share/doc/lynx/
	cp -R lynx_help debian/tmp/usr/share/doc/lynx/
	cat CHANGES `ls docs/CHANGES* |sort -t . -rn -k 2,2 -k 3,3` \
		> debian/tmp/usr/share/doc/lynx/changelog
	$(install_file) docs/CRAWL.announce docs/FM.announce \
		docs/README.chartrans PROBLEMS README \
		samples/jumpsUnix.html samples/cernrules.txt \
		samples/lynx-keymaps debian/tmp/usr/share/doc/lynx/
	$(install_dir) debian/tmp/usr/share/doc/lynx/test/
	$(install_file) test/* debian/tmp/usr/share/doc/lynx/test/
	$(install_file) debian/changelog debian/tmp/usr/share/doc/lynx/changelog.Debian
	$(install_file) debian/README.Debian debian/tmp/usr/share/doc/lynx/README.Debian
	find debian/tmp/usr/share/doc/lynx -type f -maxdepth 1 | xargs gzip -9v
	$(install_file) debian/copyright debian/tmp/usr/share/doc/lynx/

	$(install_dir) debian/tmp/usr/lib/menu/
	$(install_file) debian/menu debian/tmp/usr/lib/menu/lynx

	$(install_dir) debian/tmp/usr/share/applications
	$(install_file) debian/lynx.desktop debian/tmp/usr/share/applications/lynx.desktop

	$(install_dir) debian/tmp/usr/lib/mime/packages/
	$(install_file) debian/mime debian/tmp/usr/lib/mime/packages/lynx

	uudecode -o debian/icons/web-browser.png debian/icons/web-browser.png.uue
	$(install_dir) debian/tmp/usr/share/icons/hicolor/22x22/apps/
	$(install_file) debian/icons/web-browser.png debian/tmp/usr/share/icons/hicolor/22x22/apps/web-browser.png

	dpkg-shlibdeps debian/tmp/usr/bin/lynx.stable
	dpkg-gencontrol -isp
	chown -R root.root debian/tmp/
	chmod -R go=rX debian/tmp/
	dpkg --build debian/tmp/ ..

define checkdir
	test -f src/LYMain.c -a -f debian/rules
endef

# Below here is fairly generic really

binary: 	binary-indep binary-arch

checkroot:
	$(checkdir)
	test root = "`whoami`"

.PHONY: binary binary-arch binary-indep clean checkroot patch unpatch
